﻿using BootstrapBlazor.Components;
using SqlSugar;

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace Application.Core.Entity;

[SugarTable("User", TableDescription = "用户表")]
public class User
{
	/// <summary>主键 Id</summary>
	[SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnDescription = "主键Id")]
	[Display(Name = "主键")]
	[AutoGenerateColumn(Ignore = true)]
	public int Id { get; set; }

	/// <summary>登录名称</summary>
	[SugarColumn(Length = 64, IsNullable = false, ColumnDescription = "登录名称")]
	[Display(Name = "登录名")]
	[AutoGenerateColumn(Order = 10, Filterable = true, Searchable = true)]
	public string UserName { get; set; } = default!;

	/// <summary>显示名称</summary>
	[SugarColumn(Length = 64, IsNullable = false, ColumnDescription = "显示名称")]
	[Display(Name = "显示名称")]
	[AutoGenerateColumn(Order = 20, Filterable = true, Searchable = true)]
	public string DisplayName { get; set; } = default!;

	/// <summary>密码哈希</summary>
	[SugarColumn(Length = 256, IsNullable = false, ColumnDescription = "密码哈希")]
	[AutoGenerateColumn(Ignore = true)]
	public string PasswordHash { get; set; } = default!;

	/// <summary>是否禁用</summary>
	[SugarColumn(ColumnDescription = "是否禁用")]
	[Display(Name = "是否禁用")]
	[AutoGenerateColumn(Order = 40, Sortable = true)]
	public bool IsDisabled { get; set; } = false;

	/// <summary>创建时间(UTC)</summary>
	[SugarColumn(ColumnDescription = "创建时间(UTC)")]
	[Display(Name = "创建时间")]
	[AutoGenerateColumn(Order = 70)]
	public DateTime CreatedAt { get; set; } = DateTime.UtcNow;

	/// <summary>多对多：用户拥有的权限集合</summary>
	[Navigate(typeof(UserPermission), nameof(UserPermission.UserId), nameof(UserPermission.PermissionId))]
	[AutoGenerateColumn(Ignore = true)]
	public List<Permission> Permissions { get; set; } = [];
}
